home *** CD-ROM | disk | FTP | other *** search
/ Linux Cubed Series 3: Developer Tools / Linux Cubed Series 3 - Developer Tools.iso / devel / lang / lisp / glisp / glisp.000 / GLISP.UNIX.TAR / closunix / clos_lfg.c < prev    next >
Encoding:
C/C++ Source or Header  |  1995-04-03  |  4.3 KB  |  258 lines

  1. /*                 GRAPHIC LISP            */
  2. /*        Scritto nel 1991-94 da Zoia Andrea Michele     */
  3. /*        Via Pergola #1 Tirano (SO) Tel. 0342-704210    */
  4. /* file clos_lfg.c */
  5.  
  6. #include "clos.h"
  7.  
  8. #define chkgr()                            \
  9.   if(!lg_graphopen()){                        \
  10.     nout->node=NIL;                        \
  11.     nout->type=P_ALLNODE;                                       \
  12.     return;                                                     \
  13.   }                                                             \
  14.  
  15. #define getinit()                        \
  16.   node n;                                                       \
  17.   node ni=nin                                                   \
  18.  
  19. #define getint(v)                        \
  20.   if(!IS_CONS(nin))                                             \
  21.     error(E_FEWARGS,ERR_MERROR|ERR_TBLVL|ERR_PNODE,&ni);        \
  22.   eval(CONSLEFT(nin),nout,genv,lenv,EVAL_NORM);            \
  23.   n=calc_pointer(nout);                        \
  24.   if(!IS_VALUE(n) || !(GET_VTYPE(n)==NT_INTEGER) )              \
  25.     error(E_BADARGS,ERR_MERROR|ERR_TBLVL|ERR_PNODE,&n);         \
  26.   v=INTEGER(n);                            \
  27.   nin=CONSRIGHT(nin);
  28.  
  29. #define getstring(v)                        \
  30.   if(!IS_CONS(nin))                                             \
  31.     error(E_FEWARGS,ERR_MERROR|ERR_TBLVL|ERR_PNODE,&ni);        \
  32.   eval(CONSLEFT(nin),nout,genv,lenv,EVAL_NORM);            \
  33.   n=calc_pointer(nout);                        \
  34.   if(!IS_VALUE(n) || !(GET_VTYPE(n)==NT_STRING) )               \
  35.     error(E_BADARGS,ERR_MERROR|ERR_TBLVL|ERR_PNODE,&n);         \
  36.   v=STRING(n);                            \
  37.   nin=CONSRIGHT(nin);
  38.  
  39.  
  40. node intlist(x,y)
  41. n_int x,y;
  42. {
  43.  node c1,c2,r1,r2;
  44.  
  45.  c1=node_make();
  46.  c2=node_make();
  47.  r1=node_make();
  48.  r2=node_make();
  49.  
  50.  TYPE(r1)=TYPE(r2)|=NT_IS_VALUE+NT_INTEGER;
  51.  TYPE(c1)=TYPE(c2)|=NT_IS_CONS;
  52.  
  53.  INTEGER(r1)=x;
  54.  INTEGER(r2)=y;
  55.  
  56.  CONSLEFT(c1)=r1;
  57.  CONSRIGHT(c1)=c2;
  58.  CONSLEFT(c2)=r2;
  59.  CONSRIGHT(c2)=NIL;
  60.  
  61.  return c1;
  62.  
  63. }
  64.  
  65. void lf_graphopen LF_PARAMS
  66. {
  67.  getinit();
  68.  int m,row=0,col=0;
  69.  
  70.  getint(m);
  71.  if(m!=0 && lg_graphopen()){
  72.    lg_opengraph(0,&row,&col);
  73.  }
  74.  lg_opengraph(m,&row,&col);
  75.  nout->node=intlist((n_int)col,(n_int)row);
  76.  nout->type=P_ALLNODE;
  77. }
  78.  
  79. void lf_graphclear LF_PARAMS
  80. {
  81.  nout->node=lg_graphopen()?(lg_cleargraph(),T):NIL;
  82.  nout->type=P_ALLNODE;
  83. }
  84.  
  85.  
  86. void lf_gpencolor LF_PARAMS
  87. {
  88.  getinit();
  89.  long c;
  90.  
  91.  chkgr();
  92.  getint(c);
  93.  lg_pencolor(c);
  94. }
  95.  
  96. void lf_gpentick LF_PARAMS
  97. {
  98.  getinit();
  99.  int t;
  100.  
  101.  chkgr();
  102.  getint(t);
  103.  lg_pentick(t);
  104. }
  105.  
  106. void lf_gpentype LF_PARAMS
  107. {
  108.  getinit();
  109.  int t;
  110.  
  111.  chkgr();
  112.  getint(t);
  113.  lg_pentype(t);
  114. }
  115.  
  116.  
  117. void lf_gbrushcolor LF_PARAMS
  118. {
  119.  getinit();
  120.  long c;
  121.  
  122.  chkgr();
  123.  getint(c);
  124.  lg_brushcolor(c);
  125. }
  126.  
  127. void lf_gbrushtype LF_PARAMS
  128. {
  129.  getinit();
  130.  int t;
  131.  
  132.  chkgr();
  133.  getint(t);
  134.  lg_brushtype(t);
  135. }
  136.  
  137. void lf_gputpixel LF_PARAMS
  138. {
  139.  getinit();
  140.  int x,y,c;
  141.  
  142.  chkgr();
  143.  getint(x);getint(y);getint(c);
  144.  lg_putpixel(x,y,c);
  145. }
  146.  
  147.  
  148. void lf_ggetpixel LF_PARAMS
  149. {
  150.  getinit();
  151.  int x,y;
  152.  
  153.  chkgr();
  154.  getint(x);getint(y);
  155.  nout->type=P_ALLNODE;
  156.  nout->node=node_make();
  157.  TYPE(nout->node)|=NT_IS_VALUE+NT_INTEGER;
  158.  INTEGER(nout->node)=lg_getpixel(x,y);
  159. }
  160.  
  161.  
  162.  
  163.  
  164. void lf_gmoveto LF_PARAMS
  165. {
  166.  getinit();
  167.  int x,y;
  168.  
  169.  chkgr();
  170.  getint(x);getint(y);
  171.  lg_moveto(x,y);
  172. }
  173.  
  174. void lf_glineto LF_PARAMS
  175. {
  176.  getinit();
  177.  int x,y;
  178.  
  179.  chkgr();
  180.  getint(x);getint(y);
  181.  lg_lineto(x,y);
  182. }
  183.  
  184.  
  185.  
  186.  
  187. void lf_gfillpoly LF_PARAMS
  188. {
  189.  getinit();
  190.  int pts;
  191.  static int *points=NULL;
  192.  /* NB: è statico perchè se si alloca un array e poi avviene un errore
  193.     l'array non viene più disallocato da questa chiamata a fillpoly
  194.     l'array verrà disallocato dalla chiamata successiva, prima di essere
  195.     nuovamente riallocato */
  196.  int i;
  197.  
  198.  chkgr();
  199.  getint(pts);
  200.  if(pts<1)
  201.    error(E_BADARGS,ERR_MERROR|ERR_TBLVL|ERR_PNODE,&CONSLEFT(ni));
  202.  if(points)free((void*)points);
  203.  points=(int *)malloc(pts*sizeof(int)*2);
  204.  if(points==NULL)
  205.    error(E_NOMEMPOINTS,ERR_MERROR|ERR_TBLVL|ERR_PNODE,&CONSLEFT(ni));
  206.  for(i=0;i<pts;i++){
  207.    getint(points[i*2  ]);
  208.    getint(points[i*2+1]);
  209.  }
  210.  lg_fillpoly(pts,points);
  211.  free((void*)points);
  212.  points=NULL;
  213. }
  214.  
  215. void lf_gfillsector LF_PARAMS
  216. {
  217.  getinit();
  218.  int x,y,sa,ea,xr,yr;
  219.  
  220.  chkgr();
  221.  getint(x);getint(y);getint(sa);getint(ea);getint(xr);getint(yr);
  222.  lg_fillsector(x,y,sa,ea,xr,yr);
  223. }
  224.  
  225. void lf_gfillellipse LF_PARAMS
  226. {
  227.  getinit();
  228.  int x,y,xr,yr;
  229.  
  230.  chkgr();
  231.  getint(x);getint(y);getint(xr);getint(yr);
  232.  lg_fillellipse(x,y,xr,yr);
  233. }
  234.  
  235. void lf_gouttext LF_PARAMS
  236. {
  237.  getinit();
  238.  int x,y;
  239.  str_t s;
  240.  
  241.  chkgr();
  242.  getint(x);getint(y);getstring(s);
  243.  lg_graphtext(x,y,string_get(s,buf1));
  244. }
  245.  
  246.  
  247.  
  248.  
  249.  
  250.  
  251.  
  252.  
  253.  
  254.  
  255.  
  256.  
  257.  
  258.